//
//  RHFileCell.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2023/10/8.
//

#import "RHFileCell.h"
@interface RHFileCell()

@property (nonatomic,strong) UILabel *fileNameLab;

@property (nonatomic,strong) UILabel *fileSizeLab;
@end
@implementation RHFileCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        [self setupUI];
    }
    return self;
}

-(void)setFileModel:(RHPdfFileModel *)fileModel
{
    _fileModel = fileModel;
    self.fileNameLab.text = fileModel.fileName;
    self.fileSizeLab.text = fileModel.fileSize;
    
    [self.fileSizeLab sizeToFit];
    kWeakSelf;
    [self.fileSizeLab mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.offset(weakSelf.fileSizeLab.width+1);
    }];
}

-(void)setupUI
{
    kWeakSelf;
    UIView *bgView = kView;
    bgView.backgroundColor = [UIColor whiteColor];
    bgView.layer.cornerRadius = 8;
    bgView.layer.borderWidth = 1;
    bgView.layer.borderColor = kRGB(244, 244, 244).CGColor;
    [self.contentView addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsMake(2, 0, 2, 0));
    }];
    
    UIImageView *iconImg = kImageView;
    iconImg.contentMode = UIViewContentModeCenter;
    iconImg.image = [UIImage imageNamed:@"pdf_icon" ];
    [bgView addSubview:iconImg];
    [iconImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(bgView).offset(5);
            make.top.equalTo(bgView).offset(5);
            make.bottom.equalTo(bgView).offset(-5);
            make.width.equalTo(iconImg.mas_height);
    }];
    
    self.fileSizeLab = kLab;
    self.fileSizeLab.text = @"1.5M";
    self.fileSizeLab.font = [UIFont systemFontOfSize:14];
    self.fileSizeLab.textColor = kRGB(180, 180, 180);
    self.fileSizeLab.textAlignment = NSTextAlignmentRight;
    [bgView addSubview:self.fileSizeLab];
    [self.fileSizeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(bgView).offset(-10);
        make.centerY.equalTo(bgView);
    }];
    
    self.fileNameLab = kLab;
    self.fileNameLab.textColor = kRGB(120, 120, 120);
    self.fileNameLab.font = [UIFont systemFontOfSize:14];
    self.fileNameLab.text = @"attach file.pdf";
    self.fileNameLab.textAlignment = NSTextAlignmentLeft;
    [bgView addSubview:self.fileNameLab];
    [self.fileNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(iconImg.mas_right).offset(10);
        make.right.equalTo(weakSelf.fileSizeLab.mas_left).offset(-5);
        make.centerY.equalTo(bgView);
    }];
}

@end
